<template>
  <van-cell-group inset style="padding: 1rem; margin-top: 0.7rem" class="card-wrap">
    <div class="card">
      <div v-if="corner" class="card-corner">
        <div class="card-corner-text" :style="{ backgroundColor: corner.color || '#5c3191' }">
          {{ corner.text }}
        </div>
      </div>
      <slot name="title" :title="title">
        <div v-if="title" class="card-title">{{ title }}</div>
      </slot>
      <slot name="subTitle" :sub-title="subTitle">
        <div v-if="subTitle" class="card-sub-title">{{ subTitle }}</div>
      </slot>
      <slot name="card-content" :content="contentItemList">
        <card-item
          v-for="({ label, content, inline }, index) in contentItemList"
          :key="index"
          :title="label"
          :content="content"
          :inline="inline"
        />
      </slot>
      <slot name="tag" :tag="tags">
        <van-tag v-for="(tag, index) in tags" :key="index" class="card-tags" plain type="primary" size="medium">
          {{ tag }}
        </van-tag>
      </slot>
      <div class="card-foot">
        <slot name="card-foot"></slot>
        <div class="card-bottom">
          <span style="display: flex; align-items: center">
            <img v-if="leftBottomImg" class="card-avatar" :src="leftBottomImg" alt="头像" />
            <span style="padding-top: 0.5vw">{{ leftBottomText }}</span>
          </span>
          <span>{{ rightBottomText }}</span>
        </div>
      </div>
    </div>
  </van-cell-group>
</template>

<script lang="ts" setup>
import CardItem from '@/framework/components/DataCard/CardItem/index.vue'

withDefaults(
  defineProps<{
    title?: string
    subTitle?: string
    contentItemList?: Array<{ label: string; content: string; inline?: boolean }>
    tags?: Array<string>
    corner?: { text: string; color: string } | undefined
    leftBottomText?: string
    leftBottomImg?: string
    rightBottomText?: string
  }>(),
  {
    title: '',
    subTitle: '',
    corner: undefined,
    contentItemList: () => [],
    tags: () => [],
    leftBottomText: '',
    leftBottomImg: '',
    rightBottomText: ''
  }
)
</script>

<style scoped>
.card-wrap {
  box-shadow:
    4px 4px 10px rgba(0, 0, 0, 0.2),
    -4px -4px 10px rgba(255, 255, 255, 0.2),
    inset 0 0 0 rgba(255, 255, 255, 0.2),
    inset 0 0 0 rgba(0, 0, 0, 0.4);
}
.card {
  font-size: 3.8vw;
  color: #666;
  font-weight: lighter;
  position: relative;
}
.card-corner {
  overflow: hidden;
  position: absolute;
  top: -1rem;
  right: -1rem;
  width: 20vw;
  height: 20vw;
}
.card-corner .card-corner-text {
  color: #e8e8e8;
  display: flex;
  justify-content: center;
  align-items: center;
  transform: rotate(45deg);
  width: 30vw;
  height: 5.5vw;
  position: relative;
  left: -1vw;
  top: 3vw;
  font-size: 3.4vw;
}
.card-corner-text:before,
.card-corner-text:after {
  content: '';
  position: absolute;
  bottom: -3px;
}
.card-title,
.card-sub-title {
  max-width: 100%;
  width: fit-content;
  color: #000;
  font-size: 4.2vw;
  font-weight: bold;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  -o-text-overflow: ellipsis;
  padding-bottom: 1.5vh;
}
.card-sub-title {
  color: #666;
  font-size: 3.7vw;
  font-weight: normal;
  padding-bottom: 1vh;
}
.card-tags {
  margin-top: 1.5vh;
  margin-bottom: 1vh;
  margin-right: 1.5vw;
}
.card-foot {
  margin-top: 1vh;
}
.card-avatar {
  width: 5vw;
  height: 6vw;
  margin-right: 0.2rem;
}
.card-bottom {
  width: 100%;
  display: flex;
  justify-content: space-between;
}
</style>
